package com.example.controller.shop;

import com.example.common.Result;
import com.example.entity.shop.DamageReport;
import com.example.entity.shop.SellerProduct;
import com.example.service.shop.DamageReportService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/damageReport")
public class DamageReportController {
    @Resource
    private DamageReportService damageReportService;
@PostMapping("/insert")
    public Result insert(@RequestBody DamageReport damageReport)
    {
        damageReportService.insert(damageReport);
        return Result.success();
    }
@GetMapping("/selectAssociation")
    public Result selectAssociation( DamageReport damageReport,
                                    @RequestParam(defaultValue = "1") Integer pageNum,
                                    @RequestParam(defaultValue = "10") Integer pageSize)
    {
        System.out.println("=========="+damageReport+pageSize);
        return Result.success(damageReportService.selectAssociation(damageReport,pageNum,pageSize));
    }

    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Integer id)
    {
        damageReportService.deleteById(id);
        return Result.success();
    }

    @PostMapping("/deleteBatch")
    public Result deleteBatch(@RequestBody List<Integer> ids)
    {
        damageReportService.deleteBatch(ids);
        return Result.success();
    }

    @GetMapping("/selectByName")
    public Result selectByName(SellerProduct sellerProduct, @RequestParam(defaultValue = "1") Integer pageNum,
                               @RequestParam(defaultValue = "10") Integer pageSize)
    {
       PageInfo<DamageReport> page = damageReportService.selectByName(sellerProduct,pageNum,pageSize);
       return Result.success(page);
    }

}
